package com.itany.boot.controller;

import com.itany.boot.entity.User;
import com.itany.boot.service.UserService;
import com.itany.boot.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @date 2025/10/11
 */
@Controller
@RequestMapping("/frontUser")
public class UserController {
    
    @Autowired
    private UserService userService;
    
    /**
     * 普通用户注册接口
     * @param user 用户信息
     * @return 注册结果
     */
    @RequestMapping("/register")
    @ResponseBody
    public ResponseResult register(User user) {
        try {
            userService.register(user);
            return new ResponseResult("200", "注册成功");
        } catch (IllegalArgumentException e) {
            // 处理验证异常，返回具体的错误信息
            return new ResponseResult("400", e.getMessage());
        } catch (Exception e) {
            // 处理其他异常
            e.printStackTrace();
            return new ResponseResult("500", "注册失败，请稍后重试");
        }
    }
}
